// import { defaultRoutes } from "@/router/default";

const router = {
  state: {
    routerList: [],
    asyncRouter: [],
    init: false,
    btnPermission: []
  },
  mutations: {
    SET_ROUTER: (state, routers) => {
      // console.log('allRouterList',routers)
      state.routerList = routers;
      state.init = true;
    },
    SET_BUTTON: (state, buttons) => {
      state.btnPermission = buttons;
    },
    SET_INIT: (state, status) => {
      state.init = status;
    },
    SET_ASYNC_ROUTER: (state, router) => {
      state.asyncRouter = router;
    }
  },
  actions: {
    // 设置路由
    setRouter({ commit }, routers) {
      // let d = JSON.parse(JSON.stringify(defaultRoutes));
      // // 与默认路由合并
      // d[0].children = d[0].children.concat(routers)
      // console.log("defaultRoutes", defaultRoutes)
      commit("SET_ROUTER", routers);
    },
    // 存储异步路由，生成菜单时用到
    setAsyncRouter({ commit }, router) {
      // console.log("setAsyncRouter", router)
      commit("SET_ASYNC_ROUTER", router);
    },
    // 设置按钮权限
    setButton({ commit }, buttons) {
      commit("SET_BUTTON", buttons);
    },
    resetRouter({ commit }) {
      commit("SET_ROUTER", []);
      commit("SET_ASYNC_ROUTER", []);
      // commit("SET_BUTTON", []);
    }
  }
};

export default router;
